<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="../ct-last-updated.html">

<script>
(function() {

var assert = chai.assert;

describe('ct-last-updated', function() {
  var lastUpdated;

  describe('Updated 5 minutes ago', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      // Set the date to 5 minutes ago.
      lastUpdated.date = new Date(Date.now() - (5 * 60 * 1000));
      requestAnimationFrame(function() { done(); });
    });

    it('should have correct text', function() {
      var expected = 'Updated @ ' + lastUpdated.date.getHours() + ':' +
                     lastUpdated.date.getMinutes().toString().padLeft(2, '0');
      assert.include(lastUpdated.shadowRoot.getElementsByTagName('span')[0].innerHTML.trim(), expected);
    });

    it('should have a stale class', function() {
      var expected = 'stale_5minutes';
      assert.include(lastUpdated.shadowRoot.getElementsByTagName('span')[0].className, expected);
    });
  });

  describe('Updated 10 minutes ago', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      // Set the date to 10 minutes ago.
      lastUpdated.date = new Date(Date.now() - (10 * 60 * 1000));
      requestAnimationFrame(function() { done(); });
    });

    it('should have a stale class', function() {
      var expected = 'stale_10minutes';
      assert.include(lastUpdated.shadowRoot.getElementsByTagName('span')[0].className, expected);
    });
  });

  describe('Updated 20 minutes ago', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      // Set the date to 20 minutes ago.
      lastUpdated.date = new Date(Date.now() - (20 * 60 * 1000));
      requestAnimationFrame(function() { done(); });
    });

    it('should have a stale class', function() {
      var expected = 'stale_20minutes';
      assert.include(lastUpdated.shadowRoot.getElementsByTagName('span')[0].className, expected);
    });
  });

  describe('No updated data', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      requestAnimationFrame(function() { done(); });
    });

    it('no text should be visible', function() {
      assert.notInclude(lastUpdated.shadowRoot.querySelector('template').innerHTML.trim(), "Updated");
    });
  });

  describe('Pad minutes when less than 10', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      lastUpdated.date = Date.create('11:05');
      requestAnimationFrame(function() { done(); });
    });

    it('should have correct text', function() {
      var expected = '11:05';
      assert.include(lastUpdated.shadowRoot.innerHTML.trim(), expected);
    });
  });

  describe('Pad minutes when greater than 10', function() {
    beforeEach(function(done) {
      lastUpdated = document.createElement('ct-last-updated');
      lastUpdated.date = Date.create('11:25');
      requestAnimationFrame(function() { done(); });
    });

    it('should have correct text', function() {
      var expected = '11:25';
      assert.include(lastUpdated.shadowRoot.innerHTML.trim(), expected);
    });
  });


});

})()

</script>
